<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信公众号支付</title>
    <script type="text/javascript">

        function onBridgeReady() {

            WeixinJSBridge.invoke('getBrandWCPayRequest',  JSON.parse(document.querySelector("#prepayid").value),
                function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                       alert("支付成功");
                    }
                });
        }

        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }

    </script>
</head>
<body>
<textarea placeholder= '请输入授权码' id="prepayid" style="height: 100px; width: 100%;"></textarea>
<br>
<button onclick="onBridgeReady()" style="
    color: white;
    background-color: green;
    width: 100%;
    height: 39px;
    border-radius: 10px;
">支付</button>
</body>
</html>
